package com.kunteng.ynhxksh.controller;

import com.kunteng.ynhxksh.service.SHGKService;
import com.kunteng.ynhxksh.util.ResultMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created By ShiYun with IntelliJ IDEA on 2018/4/2 10:28
 *
 * @author: ShiYun
 * @Email: 515867726@qq.com
 * @Date: 2018/4/2
 * To change this template use File | Settings | File Templates.
 */
@Api(tags = "商户管控接口")
@RestController
@RequestMapping("/shgk")
public class SHGKController {

    Logger logger = LoggerFactory.getLogger(SHGKController.class);

    @Autowired
    private SHGKService shgkService;

    @ApiOperation(value = "统计数字", notes = "根据商户条件")
    @ApiImplicitParam(name = "date", value = "当天日期yyyy-MM-dd", required = true, paramType = "query")
    @RequestMapping(value = "/shopStatisticalNum", method = RequestMethod.GET)
    @ResponseBody
    public ResultMsg shopStatisticalNum(@RequestParam String date) {
        logger.info("shopStatisticalNum {}", date);
        JSONObject object = new JSONObject();
        try {
            object = shgkService.shopStatisticalNum(date);
            return ResultMsg.msg(0, "查询成功", object);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultMsg.msg(-1, "系统异常", e.getLocalizedMessage());
        }
    }

    @ApiOperation(value = "一周新入网商户数趋势", notes = "根据商户入网时间")
    @ApiImplicitParam(name = "date", value = "七天前日期yyyy-MM-dd", required = true, paramType = "query")
    @RequestMapping(value = "/newShopWeekNum", method = RequestMethod.GET)
    @ResponseBody
    public ResultMsg newShopWeekNum(@RequestParam String date) {
        logger.info("newShopWeekNum {}", date);
        JSONObject object = new JSONObject();
        try {
            object = shgkService.newShopWeekNum(date);
            return ResultMsg.msg(0, "查询成功", object);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultMsg.msg(-1, "系统异常", e.getLocalizedMessage());
        }
    }

    @ApiOperation(value = "今日商户交易总额区间分布", notes = "根据今日商户交易总额")
    @ApiImplicitParam(name = "date", value = "日期yyyy-MM-dd", required = true, paramType = "query")
    @RequestMapping(value = "/shopJyzeQJ", method = RequestMethod.GET)
    @ResponseBody
    public ResultMsg shopJyzeQJ(@RequestParam String date) {
        logger.info("shopJyzeQJ {}", date);
        JSONObject object = new JSONObject();
        try {
            object = shgkService.shopJyzeQJ(date);
            return ResultMsg.msg(0, "查询成功", object);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultMsg.msg(-1, "系统异常", e.getLocalizedMessage());
        }
    }

    @ApiOperation(value = "一周有交易商户数趋势", notes = "根据商户每日交易")
    @ApiImplicitParam(name = "date", value = "七天前日期yyyy-MM-dd", required = true, paramType = "query")
    @RequestMapping(value = "/shopJYNumWeek", method = RequestMethod.GET)
    @ResponseBody
    public ResultMsg shopJYNumWeek(@RequestParam String date) {
        logger.info("shopJYNumWeek {}", date);
        JSONObject object = new JSONObject();
        try {
            object = shgkService.shopJYNumWeek(date);
            return ResultMsg.msg(0, "查询成功", object);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultMsg.msg(-1, "系统异常", e.getLocalizedMessage());
        }
    }
}
